/**
 * 
 */
package com.wissen.giskard.client.payroll.controller;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.user.client.rpc.AsyncCallback;
import com.wissen.giskard.client.data.SalaryDTO;
import com.wissen.giskard.client.payroll.observer.PayRollObserver;
import com.wissen.giskard.client.services.ServiceUtil;


/**
 * @author Swapnil Sonawane
 *
 * @created date :10-Aug-2010
 */
public class PayRollController {

	private static PayRollController _instance=null;
	
	
	List<PayRollObserver> payRollObserverList = new ArrayList<PayRollObserver>();
	
	public static synchronized PayRollController getInstance()
	{
		if(_instance==null){
			_instance=new PayRollController();
		
		
		}
		return _instance;
	}
	
	public void addPayRollObserver(PayRollObserver observer)
	{
		payRollObserverList.add(observer);
	}
	
	public void displayTable()
	{
		
		ServiceUtil.getTableService().DisplayTable(displayTablecallback);
	}
	
	
	AsyncCallback<List<SalaryDTO>> displayTablecallback = new AsyncCallback<List<SalaryDTO>>() {

		@Override
		public void onFailure(Throwable caught) {
			for(PayRollObserver observer :payRollObserverList)
				observer.notifyTableDisplayFail("Error in Connecting ...");
		}

		@Override
		public void onSuccess(List<SalaryDTO> result) {
			for(PayRollObserver observer :payRollObserverList)
				observer.notifyTableDisplaySucceeded(result);
		}
	};
	
}
